MAKE   = @MAKE@
RM     = @RM@
SHELL  = @SHELL@

# The empty string, "", in PKGS is needed to avoid /bin/sh from complaining
# when @PKGS@ is/are really empty.
PKGS   = "" @subdirs@

all:
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          echo "Making $$pkg" ; \
	          ( cd $$pkg && $(MAKE) $(MAKEOPTS) ) ; \
	      fi ; \
	  done

install:
	@if [ -n "$(PREFIX)" ] ; then \
	     ./sbin/install-package -prefix=$(PREFIX) ; \
	 else \
	     ./sbin/install-package ; \
	 fi

uninstall:
	@-./sbin/uninstall-package

clean:
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) $(MAKEOPTS) clean ) ; \
	      fi ; \
	  done

rmprog:
	@-for file in bin/* sbin/* ; do \
	      case "$$file" in \
	          *.in) ;; \
	          *) $(RM) $$file ;; \
	      esac ; \
	  done

distclean-misc:
	@-$(RM) sbin/install-package
	@-$(RM) Makefile
	@-$(RM) simple.class simple.jar simple_swing.class simple_swing.jar
	@-$(RM) config.log config.status
	@-$(RM) -r autom4te*.cache

distclean: rmprog distclean-misc
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) $(MAKEOPTS) distclean ) ; \
	      fi ; \
	  done

maintainer-clean: rmprog distclean-misc
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) $(MAKEOPTS) maintainer-clean ) ; \
	      fi ; \
	  done

owner-clean: rmprog distclean-misc
	@-for pkg in $(PKGS) ; do \
	      if [ -n "$$pkg" -a -s $$pkg/Makefile ] ; then \
	          ( cd $$pkg && $(MAKE) $(MAKEOPTS) owner-clean ) ; \
	      fi ; \
	  done
	@-$(RM) configure
